﻿using System;
using System.Collections.Generic;
using HYCodeBase.TopologySuite;
using NetTopologySuite.Geometries;

namespace HYCodeBase.Geometry
{
	public class HYPolygon
	{
		public HYMulPointXYZ ShellPoints
		{
			get
			{
				return this.m_ShellPoints;
			}
			private set
			{
				this.m_ShellPoints = value;
			}
		}

		public List<HYMulPointXYZ> LstHolPoints
		{
			get
			{
				return this.m_lstHolPoints;
			}
			private set
			{
				this.m_lstHolPoints = value;
			}
		}

		public double? Area
		{
			get
			{
				if (this.m_dThisArea == null)
				{
					NtsGeometryGeter ntsGeometryGeter = NtsGeometryGeter.GetNtsGeometryGeter();
					Polygon polygon = null;
					try
					{
						ntsGeometryGeter.TryMakePolygon(this, out polygon, false);
						this.m_dThisArea = new double?(polygon.Area);
					}
					catch (Exception)
					{
					}
				}
				return this.m_dThisArea;
			}
		}

		public HYPolygon(HYMulPointXYZ inputShell, List<HYMulPointXYZ> inputHoles = null)
		{
			this.m_ShellPoints = inputShell;
			if (inputHoles != null)
			{
				this.m_lstHolPoints = new List<HYMulPointXYZ>();
				this.m_lstHolPoints.AddRange(inputHoles);
			}
		}

		public bool TryGetCenterPoint(out HYPointXYZ centerPoint)
		{
			centerPoint = null;
			return InnerPointCalculater.TryCalculateCenterPoint(this, out centerPoint);
		}

		public bool TryGetOneInnerPoint(out HYPointXYZ innerPoint)
		{
			innerPoint = null;
			return InnerPointCalculater.TryCalculateOneInnerPoint(this, out innerPoint, 3);
		}

		private HYMulPointXYZ m_ShellPoints;

		private List<HYMulPointXYZ> m_lstHolPoints;

		private double? m_dThisArea;
	}
}
